package com.edais.service.imp;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import com.edais.dao.FinancePlanOpfDao;
import com.edais.domain.Finance;
import com.edais.service.FinancePlanOpfService;

@Service

public class FinancePlanOpfServiceImp implements FinancePlanOpfService {
	private static final Log logger = LogFactory
			.getLog(FinancePlanOpfServiceImp.class);

	@Autowired
	private FinancePlanOpfDao financeDao;

	/**
	 * 获得产品列表
	 * 
	 * @return
	 * @throws Exception
	 */
	@Override
	public List<Map> getFinanceList() throws Exception {
		List<Map> listMap = new ArrayList<Map>();
		HashMap<String, Object> hashMap;
		List<Finance> financeList = financeDao.getFinanceList();
		for (Finance finance : financeList) {
			hashMap = new HashMap<String, Object>();
			hashMap.put("financeID", finance.getId());// 理财产品id
			hashMap.put("financeName", finance.getName());// 理财产品名称
			listMap.add(hashMap);
		}
		return listMap;
	}

	/**
	 * 获得产品字符串
	 * 
	 * @return
	 * @throws Exception
	 */
	@Override
	public String getFinanceString() throws Exception {
		StringBuffer sb = new StringBuffer();
		List<Finance> financeList = financeDao.getFinanceList();
		if (financeList != null && financeList.size() > 0) {
			sb.append(financeList.get(0).getId());// 理财产品id
			if (financeList.size() > 1) {
				for (int i = 1; i < financeList.size(); i++) {
					sb.append(",");
					sb.append(financeList.get(i).getId());// 理财产品id
				}
			}
		} else {
			sb.append("109");
		}
		return sb.toString();
	}

}
